<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
%>
<!DOCTYPE html>
<html>
<fmt:bundle basename="text">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>${title}</title>
        <link rel="stylesheet"
              href="<%=basePath%>/bootstrap/css/bootstrap.min.css">
        <link rel="stylesheet" href="<%=basePath%>/css/font-awesome.min.css">
        <link rel="stylesheet" href="<%=basePath%>/css/ionicons.min.css">
        <link rel="stylesheet" href="<%=basePath%>/dist/css/AdminLTE.min.css">
        <link rel="stylesheet" href="<%=basePath%>/toastr/toastr.css"
              type="text/css"/>
        <link rel="stylesheet"
              href="<%=basePath%>/dist/css/skins/_all-skins.min.css">
        <link rel="stylesheet" href="<%=basePath%>/fileupload/fileinput.min.css"
              type="text/css"/>
        <link rel="stylesheet"
              href="<%=basePath%>/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css">
        <link rel="stylesheet"
              href="<%=basePath%>/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css">
        <link rel="stylesheet" href="<%=basePath%>/plugins/iCheck/all.css">
        <link rel="stylesheet" type="text/css"
              href="<%=basePath%>/pagination/style/pagination.css" media="screen">
        <link rel="stylesheet"
              href="<%=basePath%>/plugins/iziModal/css/iziModal.min.css">
        <link rel="stylesheet"
              href="<%=basePath%>/plugins/select2/select2.min.css">
        <link rel="stylesheet" href="<%=basePath%>/plugins/iCheck/all.css">
        <link rel="stylesheet" href="<%=basePath%>/plugins/loaders/loaders.css"/>
        <link rel="stylesheet" href="<%=basePath%>/plugins/flavr/animate.css"/>
        <link rel="stylesheet" href="<%=basePath%>/plugins/flavr/flavr.css"/>
    </head>
    <body class="hold-transition skin-blue sidebar-mini">
    <div id="request-div" style="position: absolute;width: 100%;height: 100%;z-index: 10;display: none;">
        <img src='../images/request-sending.gif' style="position: relative;top: 50%;left: 50%;width: 70px;height: 70px">
    </div>
    <div class="wrapper">

        <header class="main-header">
            <jsp:include page="../logo.jsp"></jsp:include>
            <nav class="navbar navbar-fixed-top">
                <a class="sidebar-toggle" data-toggle="offcanvas" role="button" onclick="show()">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </a>
                <jsp:include page="../menuTop.jsp"></jsp:include>
            </nav>

        </header>

        <!-- =============================================== -->

        <!-- Left side column. contains the sidebar -->
        <aside class="main-sidebar">
            <jsp:include page="../menu.jsp"></jsp:include>
            <!-- /.sidebar -->
        </aside>

        <!-- =============================================== -->

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper" style="padding-top:50px;">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <ol class="breadcrumb">
                    <li class="text-muted"><i class="fa fa-th"></i>&nbsp;&nbsp;医院管理</li>
                    <li class="text-muted"><i class="fa fa-circle-o"></i>&nbsp;&nbsp;上传设备</li>
                </ol>
            </section>

            <section class="content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box box-info">
                            <div class="box-body">
                                <form id="myForm" action="<%=basePath %>/assets/hospitalExcel" method="post"
                                      class="form-horizontal">
                                    <input type="hidden" name="type" value="${type}">
                                    <br/>
                                    <div class="form-group">
                                        <label for="files"
                                               class="col-sm-1 control-label text-warning">上传文件</label>
                                        <div class="col-sm-8">
                                            <input type="file" class="file" data-show-preview="false"
                                                   name="files" id="files" onchange="fileOnchange()">
                                        </div>
                                        <div class="col-sm-1">
                                            <button type="button" class="btn btn-info" onclick="hospitalExcel()">
                                                上传
                                            </button>
                                        </div>
                                        <div class="col-sm-1">
                                            <button type="button" class="btn btn-info" onclick="modalDownload()">下载模版
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="form-group col-md-12" id="checkExecl" style="display: none;">
                                <div class="col-md-2">
                                    <button type="button" class="btn btn-info" id="checkButton"
                                            onclick="checkExcelAssetsInfo(this)">检查
                                    </button>
                                    <button type="button" class="btn btn-info" id="saveButton"
                                            onclick="saveExcelAssetsInfo(this)">保存
                                    </button>
                                </div>
                            </div>


                            <div class="box-body">
                                <div class="form-group col-md-12" id="errorDiv" style="color:red">

                                </div>
                            </div>


                            <div class="box-body table-responsive" id="myTable" style="display: none;height:400px;">
                                <table class="table table-bordered table-striped table-hover">
                                    <tbody id="table_data">
                                    <tr class="info">
                                        <th class="text-center text-muted" style="width:30px">#</th>
                                        <th class="text-center text-muted">设备名称</th>
                                        <th class="text-center text-muted">设备型号</th>
                                        <th class="text-center text-muted">序列号</th>
                                        <th class="text-center text-muted">医院</th>
                                        <th class="text-center text-muted">厂家</th>
                                        <th class="text-center text-muted">维修商</th>
                                        <th class="text-center text-muted">科室</th>
                                        <th class="text-center text-muted">资产编号</th>
                                        <th class="text-center text-muted">产地</th>
                                        <th class="text-center text-muted">规格</th>
                                        <th class="text-center text-muted">单价</th>
                                        <th class="text-center text-muted">数量</th>
                                        <th class="text-center text-muted">附件</th>
                                        <th class="text-center text-muted">保养周期(月)</th>
                                        <th class="text-center text-muted">上次保养时间</th>
                                        <th class="text-center text-muted">安装日期</th>
                                        <th class="text-center text-muted">验收日期</th>
                                        <th class="text-center text-muted">购买日期</th>
                                        <th class="text-center text-muted">出厂日期</th>
                                        <th class="text-center text-muted">负责人</th>
                                        <th class="text-center text-muted">设备状态</th>
                                        <th class="text-center text-muted">68分类一级</th>
                                        <th class="text-center text-muted">68分类二级</th>
                                        <th class="text-center text-muted">备注</th>
                                    </tr>
                                    </tbody>
                                    <tfoot id="myTbody">


                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>

        <div id="modal">

        </div>

        <!-- =============================================== -->

        <footer class="main-footer">
            <div class="pull-right hidden-xs">
                <b>Version</b> 1.0.0
            </div>
            <strong>Copyright &copy; 2019 <a href="http://almsaeedstudio.com">Topmed</a>.</strong> All rights reserved.
        </footer>
        <jsp:include page="../menuRight.jsp"></jsp:include>
    </div>
    <!-- ./wrapper -->
    <script src="<%=basePath%>/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="<%=basePath%>/bootstrap/js/bootstrap.min.js"></script>
    <script src="<%=basePath%>/plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <script src="<%=basePath%>/plugins/fastclick/fastclick.js"></script>
    <script src="<%=basePath%>/dist/js/app.min.js"></script>
    <script src="<%=basePath%>/dist/js/demo.js"></script>
    <script src="<%=basePath%>/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
    <script src="<%=basePath%>/toastr/toastr.js"></script>
    <script src="<%=basePath%>/pagination/js/jquery.pagination.min.js"></script>
    <script src="<%=basePath%>/js/overallSituation.js"></script>
    <script src="<%=basePath%>/fileupload/fileinput.min.js"></script>
    <script src="<%=basePath%>/fileupload/zh.js"></script>
    <script
            src="<%=basePath%>/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
    <script
            src="<%=basePath%>/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script
            src="<%=basePath%>/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="<%=basePath%>/plugins/select2/select2.min.js"></script>
    <script src="<%=basePath%>/plugins/select2/i18n/zh-CN.js"></script>
    <script src="<%=basePath%>/plugins/iCheck/icheck.min.js"></script>
        <%-- <script src="<%=basePath%>/js/contract.js"></script> --%>
    <script src="<%=basePath%>/plugins/iziModal/js/iziModal.min.js"></script>
    <script src="<%=basePath%>/plugins/flavr/flavr.min.js"></script>

    <script type="text/javascript">


        function show() {
            $("#errorDiv").hide();
            $("#checkButton").show();
            $("#saveButton").hide();

            var filesValue = $("#files").val();
            if (filesValue == null || filesValue == "") {
                new $.flavr({
                    content: "请上传文件!"
                })
                return;
            }
            var last = filesValue.lastIndexOf(".");
            var suffix = filesValue.substring(last + 1, filesValue.length);
            if (suffix != "xlsx") {
                new $.flavr({
                    content: "上传的文件格式有误，请上传后缀名为xlsx的excel文件!"
                })
                return;
            }
        }

        var bool =false;
        function hospitalExcel() {
            if(!bool){
                bool = true;

                $("#myTbody").html("");
                var formData = new FormData($("#myForm")[0]);
                $.ajax({
                    type: "POST",
                    url: "<%=basePath%>/device/deviceExcel",
                    dataType: "json",
                    data: formData,//整个表单提交
                    async: false,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                        if(data.ret == 200){
                            var html="";
                            $.each(data.data,function (index,item) {
                                html+="<tr><td class='text-center text-muted'>"+(index+1)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.deviceName==null?'':item.deviceName)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.deviceModel==null?'':item.deviceModel)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.sn==null?'':item.sn)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.hospitalName==null?'':item.hospitalName)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.manufacturerName==null?'':item.manufacturerName)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.maintainerName==null?'':item.maintainerName)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.department==null?'':item.department)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.assetsNo==null?'':item.assetsNo)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.placeOrigin==null?'':item.placeOrigin)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.specifications==null?'':item.specifications)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.priceStr==null?'':item.priceStr)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.quantityStr==null?'':item.quantityStr)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.attachment==null?'':item.attachment)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.upkeepCycleStr==null?'':item.upkeepCycleStr)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.lastUpkeepDate==null?'':item.lastUpkeepDate)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.installDate==null?'':item.installDate)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.acceptanceDate==null?'':item.acceptanceDate)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.purchaseDate==null?'':item.purchaseDate)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.manufactureDate==null?'':item.manufactureDate)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.responsiblePerson==null?'':item.responsiblePerson)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.deviceStatusStr==null?'':item.deviceStatusStr)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.deviceTypeStr==null?'':item.deviceTypeStr)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.deviceTypeSubStr==null?'':item.deviceTypeSubStr)+"</td>" +
                                    "<td class='text-center text-muted'>"+(item.remark==null?'':item.remark)+"</td>" +
                                    "</tr>"
                            });
                            if (data.data.length > 9) {
                                $("#myTable").css("height", "auto");
                            }
                            $("#myTbody").html(html);
                            $("#myTable").show();
                            $("#checkExecl").show();
                            bool = false;

                        }else{
                            flavrShowByTime(data.msg,null,"danger",false);
                            bool = false;
                        }
                    },
                    failure: function () {
                        bool = false;
                    }
                });
            }
        }

        function checkExcelAssetsInfo() {
            $.ajax({
                type: "POST",
                url: "<%=basePath%>/device/checkExcelDevice",
                dataType: "json",
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    try {
                        if (data.ret == 200) {
                            var errorMessageList = data.data.errorMessage;
                            var bl = data.data.bool;
                            if (!bl) {
                                var str = "";
                                for (var i = 0; i < errorMessageList.length; i++) {
                                    str = str + "<h6>" + errorMessageList[i] + ",</h6>"
                                }
                                $("#errorDiv").html(str);
                                $("#errorDiv").show();
                                $("#saveButton").hide();
                                $("#checkButton").show();
                            } else {
                                $("#errorDiv").html("检查成功");
                                $("#errorDiv").show();
                                $("#saveButton").show();
                                $("#checkButton").hide();
                            }
                        } else {
                            flavrShowByTime(data.msg,null,"danger",false);
                        }
                    } catch (error) {
                        flavrShowByTime(data.msg,null,"danger",false);
                    }
                }
            });

        }

        function saveExcelAssetsInfo() {
            var url = "<%=basePath%>/device/saveDeviceByExecl"
            $.ajax({
                type: "POST",
                url: url,
                dataType: "json",
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    try {
                        if (data.ret == 200) {
                            flavrShow(data.msg, url, "success", true);
                            $("#errorDiv").html(data.msg);
                            $("#saveButton").hide();
                            bool = false;
                        } else {
                            flavrShow(data.msg, url, "danger", false);
                            bool = false;
                        }
                    } catch (error) {
                        flavrShow("保存出现异常", url, "danger", false);
                        bool = false;
                    }
                },
                failure: function () {
                    flavrShow("保存失败", url, "danger", false);
                    bool = false;
                }
            });

        }

        function fileOnchange() {
            $(".fileinput-upload").hide();
            $(".fileinput-remove-button").hide();
            $("#errorDiv").html("");
            $("#errorDiv").hide();
            $("#myTbody").html("");
            $("#myTable").hide();
            $("#checkButton").show();
            $("#saveButton").hide();
        }

        $(document).ready(function () {
            menuCss("设备管理");
            $(".btn-file").addClass("btn-info");
            //$(".input-group-btn").addClass("btn");
            $(".btn-file").find(".hidden-xs").html("浏览");
        });

        function modalDownload() {
            location.href = "<%=basePath%>/fileupload/Excel/device.xlsx";
        }




    </script>
    </body>
</fmt:bundle>
</html>
